<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a="http://richfaces.org/a4j"
    template="layout/templateList.xhtml">

<ui:define name="body">
	
	 <script type="text/javascript">
        function setCaretToEnd (e) {
            var control = $((e.target ? e.target : e.srcElement).id);
            if (control.createTextRange) {
                var range = control.createTextRange();
                range.collapse(false);
                range.select();
            }
            else if (control.setSelectionRange) {
                control.focus();
                var length = control.value.length;
                control.setSelectionRange(length, length);
            }
            control.selectionStart = control.selectionEnd = control.value.length;
        } 

    </script>

	<table align="right">
		<tr>
			<td>
				<h:commandButton immediate="true"
					onclick="abrirPopup('help_online/help_racas.seam');" 
					title="Ajuda Online"
					alt="Ajuda Online"
					image="img/help_peq.jpg"/>
			</td>
		</tr>
	</table>

	<h2 class="title"><a href="#">Gerenciar Raças</a></h2><br/>
	
		<p><b>Nota:</b> Para facilitar a sua vida, já criamos para você as principais raças existentes no mercado.
		Fique a vontade para fazer modificações e/ou inclusões de novas. 
		</p>
		<h:form id="racaForm">
			<h:panelGrid columns="1" rendered="#{identity.hasRole('GERENCIAR_RACAS_GRAVAR')}">
			
				<s:decorate template="/layout/edit.xhtml">
					<ui:define name="label">Nome:</ui:define>
					<h:inputText value="#{manterRacaController.racaEdicao.dscNome}"
						required="true"
						style="width: 300px;"
						maxlength="200"
						onkeydown="Mascara(this,Maiusculo)"
						onkeyup="Mascara(this,Maiusculo)"/>
				</s:decorate>
				
				<s:decorate template="/layout/edit.xhtml">
					<ui:define name="label">Porte:</ui:define>
					<s:decorate template="/layout/editTable.xhtml">
		        		<h:selectOneMenu value="#{manterRacaController.racaEdicao.porte}" required="true">
							<f:selectItem itemLabel="SELECIONE" itemValue=""/>	
							<f:selectItem itemLabel="PEQUENO" itemValue="P"/>
							<f:selectItem itemLabel="MÉDIO" itemValue="M"/>
							<f:selectItem itemLabel="GRANDE" itemValue="G"/>
						</h:selectOneMenu>
					</s:decorate>
				</s:decorate>
				
			</h:panelGrid>
			
			<div class="actionButtons">
	            <h:commandButton id="submit" value="Salvar" action="#{manterRacaController.salvar}"
	            	rendered="#{identity.hasRole('GERENCIAR_RACAS_GRAVAR')}"
	            	onclick="javascript:if(!confirm('Tem certeza que deseja salvar?'))return false;"/>
	        	<a:commandButton id="new" value="Cancelar" action="#{manterRacaController.cancelar}"
	        		rendered="#{identity.hasRole('GERENCIAR_RACAS_GRAVAR')}"
	        		ajaxSingle="true"
	        		reRender="racaForm"/>
	        </div>
		</h:form>
		<br/><br/>		
		
		<h:form id="racasForm">			
	        <rich:dataTable value="#{manterRacaController.listaRacas}" var="_raca"
	        	rows="10"
	        	id="tabelaRacas">
	        	
	        	<f:facet name="header">
		        	<rich:columnGroup>
		        		<rich:column>
		        			<h:selectBooleanCheckbox value="#{manterRacaController.selecionadoTodos}">
		        				<a:support event="onchange" action="#{manterRacaController.selecionaTodos()}" reRender="tabelaRacas"/>
		        			</h:selectBooleanCheckbox>
		        		</rich:column>
		        		<rich:column>
		        			<h:outputText value="NOME" />
		        		</rich:column>
		        		<rich:column>
		        			<h:outputText value="PORTE" />
		        		</rich:column>
		        		<rich:column>
		        			<h:outputText value="" />
		        		</rich:column>
		        	</rich:columnGroup>
	        	</f:facet>
	        	
	        	<rich:column>
	        		<f:facet name="header">
	        		</f:facet>
	        		<h:selectBooleanCheckbox value="#{_raca.selecionado}" />
	        	</rich:column>
	        	
	        	<rich:column filterMethod="#{manterRacaController.filtrarRacasPorNome}">
	        		<f:facet name="header">
	        			<h:inputText value="#{manterRacaController.filtroNome}" id="input"
	        				title="Digite o filtro e aguarde a pesquisa automática">
	                        <a:support event="onkeyup" reRender="tabelaRacas, scrollerRacas"
	                            ignoreDupResponses="true" requestDelay="500"
	                            oncomplete="setCaretToEnd(event);"/>
	                    </h:inputText>
	        		</f:facet>
	        		<h:outputText value="#{_raca.dscNome}"/>
	        	</rich:column>
	        	
	        	<rich:column filterMethod="#{manterRacaController.filtrarRacasPorPorte}">
	        		<f:facet name="header">
	        			<h:inputText value="#{manterRacaController.filtroPorte}" id="inputPorte"
	        				title="Digite o filtro e aguarde a pesquisa automática">
	                        <a:support event="onkeyup" reRender="tabelaRacas, scrollerRacas"
	                            ignoreDupResponses="true" requestDelay="500"
	                            oncomplete="setCaretToEnd(event);"/>
	                    </h:inputText>
	        		</f:facet>
	        		<h:outputText value="#{_raca.porteExtenso}" />
	        	</rich:column>
	        	
	        	<rich:column rendered="#{identity.hasRole('GERENCIAR_RACAS_GRAVAR')}">
	        		<f:facet name="header"></f:facet>
	        		<h:commandLink value="EDITAR"
	        			action="#{manterRacaController.editar(_raca)}"/>	
	        	</rich:column>
	        </rich:dataTable>
	        
	        <rich:datascroller for="tabelaRacas" id="scrollerRacas"/>
	        <br/>
	        <div class="actionButtons">
	        	<h:commandButton id="remove" value="Excluir" action="#{manterRacaController.excluir}"
	        		rendered="#{identity.hasRole('GERENCIAR_RACAS_EXCLUIR')}"
	        		onclick="javascript:if(!confirm('Tem certeza que deseja excluir a(s) raça(s) selecionada(s)?'))return false;"/>
	        </div>
	        
	    </h:form>

 </ui:define>
</ui:composition>
